/**
 * 检查数组中的指定键值是否唯一
 * @param arr 要检查的数组
 * @param keyPropName 键名，默认为'key'
 * @returns 如果所有键值都唯一则返回true，否则返回false
 */
export const isUniqueKey = <T extends Record<string, any>>(
    arr: T[],
    keyPropName: keyof T = 'key' as keyof T
): boolean => {
    if (!Array.isArray(arr) || arr.length === 0) {
        return true;
    }

    const keySet = new Set<any>();

    for (const item of arr) {
        if (item[keyPropName] === undefined) {
            continue; // 跳过没有该属性的项
        }

        const keyValue = item[keyPropName];
        if (keySet.has(keyValue)) {
            return false; // 发现重复键值
        }
        keySet.add(keyValue);
    }

    return true;
};




export function formatNumberWithCommas(num: number,fixed:number = 1): string {
    const fixedNum = num.toFixed(fixed);
    const parts = fixedNum.split(".");
    let integerPart = parts[0];
    const decimalPart = parts.length > 1 ? "." + parts[1] : "";
    const formattedIntegerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return formattedIntegerPart + decimalPart;
}